package cn.kzgg.product.service.impl;

import cn.kzgg.pet.domain.Pet;
import cn.kzgg.pet.domain.PetOnlineAuditLog;
import cn.kzgg.product.domain.Product;
import cn.kzgg.product.mapper.ProductMapper;
import cn.kzgg.product.service.IProductService;
import cn.kzgg.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author KZGG
 * @since 2022-06-30
 */
@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public void onsale(List<Long> ids) {
        for (Long id : ids) {
            Product product = productMapper.loadById(id);

        /*//审核宠物
        for (Long id : ids) {
            //拿到这个宠物
            Pet pet = productMapper.loadById(id);
            //审核名字
            StringBuilder sb = new StringBuilder();
            //审核不通过，记录日志，下一个继续
            if(sb.toString().length()>1){
                PetOnlineAuditLog log = new PetOnlineAuditLog();
                log.setPetId(pet.getId());
                log.setNote(sb.toString());
                petOnlineAuditLogMapper.save(log);
            }*/
            //2.通过修改状态和时间
            Map<String, Object> map = new HashMap<>();
            map.put("id",id);
            map.put("onSaleTime",new Date());
            productMapper.onsale(map);


        }
    }

    /**
     * 服务下架
     * @param ids
     */
    @Override
    public void offsale(List<Long> ids) {
            Map<String, Object> map = new HashMap<>();
            map.put("ids",ids);
            map.put("offSaleTime",new Date());
            productMapper.offSale(map);

        }
}
